import { uniqueId } from 'lodash'

const modules = import.meta.globEager('./modules/*.js')
const menus = {}
for (const key in modules) {
  menus[key.substring(10, key.lastIndexOf('.'))] = handleMenu(modules[key].default)
}

// 处理menu的path为空的问题
function handleMenu(menu) {
  return {
    ...menu,
    ...menu.children ? { children: handlePath(menu.children) } : {}
  }
}
function handlePath(menus) {
  return menus.map(menu => ({
    ...menu,
    path: menu.path || uniqueId('taie-menu-'),
    ...menu.children ? { children: handlePath(menu.children) } : {}
  }))
}

export default {
  ...menus
}
